#include "OneObjRenderer.hpp"
#include <Utility\StringPrintf.hpp>

namespace zzz {
OneObjRenderer::OneObjRenderer()
{
  pCurObjArcBall_=&objArcBall_;
  pCurEnvArcBall_=NULL;
}

void OneObjRenderer::AfterOnSize(unsigned int nType, int cx, int cy)
{
  camera_.OnSize(nType, cx, cy);
  objArcBall_.OnSize(nType, cx, cy);
}

void OneObjRenderer::SetupCamera()
{
  camera_.ApplyGL();
  objArcBall_.ApplyGL();
}

void OneObjRenderer::OnLButtonDown(unsigned int nFlags,int x,int y)
{ 
  if (!lockArcBall_) {
    objArcBall_.OnLButtonDown(nFlags, x, y);
  }
}

void OneObjRenderer::OnLButtonUp(unsigned int nFlags,int x,int y)
{
  objArcBall_.OnLButtonUp(nFlags, x, y);
}

void OneObjRenderer::OnMouseMove(unsigned int nFlags,int x,int y)
{
  if (!lockArcBall_) {
    objArcBall_.OnMouseMove(nFlags, x, y);
    Redraw();
  }
  ArcBallRenderer::OnMouseMove(nFlags, x, y);
}

void OneObjRenderer::OnSize(unsigned int nType, int cx, int cy)
{
  if (cy > 0) {
    objArcBall_.OnSize(nType, cx,cy);
  }
  ArcBallRenderer::OnSize(nType,cx,cy);
}

void OneObjRenderer::ResetArcball()
{
  objArcBall_.Reset();
}

void OneObjRenderer::CreateMsg()
{
  SStringPrintf(msg_,"Res: %d x %d, SPF: %lf = FPS: %lf",width_,height_,SPF_,FPS_);
}

void OneObjRenderer::DrawObj()
{
  glColor3f(1.0,1.0,1.0);
  glBegin(GL_QUADS);
  glVertex3d(-1,-1,0);
  glVertex3d(1,-1,0);
  glVertex3d(1,1,0);
  glVertex3d(-1,1,0);
  glEnd();
}

bool OneObjRenderer::InitData()
{
  objArcBall_.Init(this);
  return ArcBallRenderer::InitData();
}

}